package com.ewzj.bigdata.mvp.ui.adapter

import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import android.support.v4.app.FragmentStatePagerAdapter
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.astuetz.PagerSlidingTabStrip
import com.ewzj.bigdata.R
import kotlin.properties.Delegates



/**
 * author:zhangjing
 * 作用:
 * return:
 */
class TabAdapter(val fragments:List<Fragment>,manager: FragmentManager) :FragmentStatePagerAdapter(manager),PagerSlidingTabStrip.CustomTabProvider{
    override fun getCustomTabView(parent: ViewGroup, position: Int): View {
        val view = View.inflate(parent.getContext(), R.layout.mypsts_tab, null)
        return view
    }

    override fun tabUnselected(tab: View?) {
        (tab as TextView).setTextColor(tab.getResources().getColor(R.color.color_black))
    }

    override fun tabSelected(tab: View?) {
        (tab as TextView).setTextColor(tab.getResources().getColor(R.color.maingreen))
    }

    var titles:List<String> by Delegates.notNull<List<String>>();
    override fun getItem(position: Int): Fragment {
        return fragments[position]
    }

    override fun getCount(): Int {
        return fragments.size
    }

    constructor(fragments:List<Fragment>,manager: FragmentManager,titles:List<String>):this(fragments,manager){
        this.titles=titles
    }

    override fun getPageTitle(position: Int): CharSequence {
        return titles[position]
    }
}